package TangramBase;

import TangramCore.Dilek;
import TangramCore.Hladina;
import TangramCore.HladinaObrys;
import TangramCore.Obrazec;
import TangramCore.Obrys.ObrysData;
import TangramCore.Skladacka;
import java.awt.Cursor;
import java.awt.Paint;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.io.IOException;
import java.util.ArrayList;

public class ObrazecShow extends Obrazec implements /*DragSourceListener,*/ DragGestureListener{
	static final long serialVersionUID = 24362462L;
	
    DragSource dragSource = null;
    ArrayList<Hladina> hladiny;
    
    public static class ObrazecTransferable implements Transferable {
        
        public Dilek[] d; ObrysData od;
        public int vzhled;
        public static DataFlavor flavorObrazec = new DataFlavor(ObrazecTransferable.class,"Obrazec");
        
        public ObrazecTransferable(HladinaObrys h, int v){
            d = h.getDilky();
            od = h.getObrys().od;
            vzhled = v;
        }
        
        public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
            if(flavor.equals(flavorObrazec)){
                return this;
            }
            else
                throw new UnsupportedFlavorException(flavor);
        }

        public DataFlavor[] getTransferDataFlavors() {
            return new DataFlavor[]{flavorObrazec};
        }

        public boolean isDataFlavorSupported(DataFlavor flavor) {
            return flavor.equals(flavorObrazec);
        }
    
    
    }
    public ObrazecShow(Skladacka skl, Paint pb, ArrayList<Hladina> a){
        super(skl, pb, a, Obrazec.MOD_SHOW);
        hladiny = a;
        dragSource = new DragSource();
        dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY, this);
    }

    /*public void dragDropEnd(DragSourceDropEvent dsde) {
    }

    public void dragEnter(DragSourceDragEvent dsde) {
    }

    public void dragExit(DragSourceEvent dse) {
    }

    public void dragOver(DragSourceDragEvent dsde) {
    }

    public void dropActionChanged(DragSourceDragEvent dsde) {
    }*/
    
    public void dragGestureRecognized(DragGestureEvent dge) {
        dge.startDrag(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR), new ObrazecTransferable((HladinaObrys)hladiny.get(0), Hladina.VZHLED_OBRYS));
    }

}
